import { stat } from 'fs';
import GlobalConfig from '../config/GlobalConfig';
import { createArticle, deleteArticleByName, updateArticle, defaultArticleModel, ArticleType, getArticles } from '/@/request/articles';
import { staticRoutes } from '/@/router/route';
import StrUnit from './StrUnit';
import { debug } from 'console';
export default class AllMap {
	public static jijieDefaultParam = { symbol: this.getImaByStatus('集结点', '集结点'), status: '集结点', htmlcontentstr: '' };
	public static baozhangDefaultParam = { symbol: this.getImaByStatus('防空警报点', '防空警报点'), status: '防空警报点', htmlcontentstr: '' };
	public static supportDefaultParam = { symbol: this.getImaByStatus('保障点', '保障点'), status: '保障点', htmlcontentstr: '' };
	public static wuziDefaultParam = { symbol: this.getImaByStatus('物资点', '物资点'), status: '物资点', htmlcontentstr: '' };
	public static duiwuDefaultParam = { symbol: this.getImaByStatus('队伍点', '队伍点'), status: '队伍点', htmlcontentstr: '' };
	public static zhihuiDefaultParam = { symbol: this.getImaByStatus('人防点', '人防点'), status: '人防点', htmlcontentstr: '' };
	public static jingjiDefaultParam = { symbol: this.getImaByStatus('经济目标', '经济目标'), status: '经济目标', htmlcontentstr: '' };
	public static luxianHideArr: any[] = [];
	public static luxianLineHideArr: any[] = [];
	public static sushanHideArr: any[] = [];
	public static sushanLineHideArr: any[] = [];
	public static yingbiHideArr: any[] = [];
	public static yingbiLineHideArr: any[] = [];
	public static jijieHideArr: any[] = [];
	public static baozhangHideArr: any[] = [];
	public static wuziHideArr: any[] = [];
	public static zhanyeHideArr: any[] = [];
	public static zhihuiHideArr: any[] = [];
	public static jingjiHideArr: any[] = [];
	public static suportHideArr: any[] = [];
	public static changeDisplayArr: any[] = [];
	public static clear() {
		this.luxianHideArr = [];
		this.luxianLineHideArr = [];

		this.sushanHideArr = [];
		this.sushanLineHideArr = [];

		this.yingbiHideArr = [];
		this.yingbiLineHideArr = [];

		this.jijieHideArr = [];
		this.baozhangHideArr = [];
		this.wuziHideArr = [];
		this.zhanyeHideArr = [];
		this.zhihuiHideArr = [];
		this.jingjiHideArr = [];
		this.changeDisplayArr = [];
		this.suportHideArr = [];
	}
	public static updateChangeDisplay(state: any) {
		if (this.changeDisplayArr.length > 0)
			state.myChart.setOption({
				series: [...this.changeDisplayArr],
			});

		this.changeDisplayArr = [];
	}
	public static moveOne(state: any, name: string, importance: string, lng: string, lat: string) {
		if (importance == '集结点') {
			this.toMoveOne(state, '集结点', name, state.jijieDian, this.jijieHideArr, lng, lat);
			return;
		}
		if (importance == '防空警报点') {
			this.toMoveOne(state, '防空警报点', name, state.baozhangDian, this.baozhangHideArr, lng, lat);
			return;
		}
		if (importance == '保障点') {
			this.toMoveOne(state, '保障点', name, state.supportDian, this.suportHideArr, lng, lat);
			return;
		}
		if (importance == '队伍点') {
			this.toMoveOne(state, '队伍点', name, state.zhanyeDian, this.zhanyeHideArr, lng, lat);
			return;
		}
		if (importance == '人防点') {
			this.toMoveOne(state, '人防点', name, state.zhihuiDian, this.zhihuiHideArr, lng, lat);
			return;
		}
		if (importance == '经济目标') {
			this.toMoveOne(state, '经济目标', name, state.jingjiDian, this.jingjiHideArr, lng, lat);
			return;
		}
		if (importance == '物资点') {
			this.toMoveOne(state, '物资点', name, state.wuziDian, this.wuziHideArr, lng, lat);
			return;
		}
	}
	public static displayOne(state: any, name: string, importance: string) {
		if (importance == '疏散路线') {
			this.convertArrToDisplay(state, '路线点', name, state.luxianDian, this.luxianHideArr);
			this.convertArrToDisplay(state, '疏散路线', name, state.shusanLuxianData, this.luxianLineHideArr);
			return;
		}
		if (importance == '疏散地域') {
			this.convertArrToDisplay(state, '疏散地域点', name, state.shusandiyuDian, this.sushanHideArr);
			this.convertArrToDisplay(state, '疏散地域', name, state.shusanDiyuData, this.sushanLineHideArr);
			return;
		}
		if (importance == '隐蔽地域') {
			this.convertArrToDisplay(state, '隐蔽地域点', name, state.yinbidiyuDian, this.yingbiHideArr);
			this.convertArrToDisplay(state, '隐蔽地域', name, state.yinbiDiyuData, this.yingbiLineHideArr);
			return;
		}
		if (importance == '集结点') {
			this.convertArrToDisplay(state, '集结点', name, state.jijieDian, this.jijieHideArr);
			return;
		}
		if (importance == '防空警报点') {
			this.convertArrToDisplay(state, '防空警报点', name, state.baozhangDian, this.baozhangHideArr);
			return;
		}
		if (importance == '保障点') {
			this.convertArrToDisplay(state, '保障点', name, state.supportDian, this.suportHideArr);
			return;
		}
		if (importance == '队伍点') {
			this.convertArrToDisplay(state, '队伍点', name, state.zhanyeDian, this.zhanyeHideArr);
			return;
		}
		if (importance == '人防点') {
			this.convertArrToDisplay(state, '人防点', name, state.zhihuiDian, this.zhihuiHideArr);
			return;
		}
		if (importance == '经济目标') {
			this.convertArrToDisplay(state, '经济目标', name, state.jingjiDian, this.jingjiHideArr);
			return;
		}
		if (importance == '物资点') {
			this.convertArrToDisplay(state, '物资点', name, state.wuziDian, this.wuziHideArr);
			return;
		}
	}
	public static hideOne(state: any, name: string, importance: string) {
		if (importance == '疏散路线') {
			this.convertArrToHide(state, '路线点', name, state.luxianDian, this.luxianHideArr);
			this.convertArrToHide(state, '疏散路线', name, state.shusanLuxianData, this.luxianLineHideArr);
			return;
		}
		if (importance == '疏散地域') {
			this.convertArrToHide(state, '疏散地域点', name, state.shusandiyuDian, this.sushanHideArr);
			this.convertArrToHide(state, '疏散地域', name, state.shusanDiyuData, this.sushanLineHideArr);
			return;
		}
		if (importance == '隐蔽地域') {
			this.convertArrToHide(state, '隐蔽地域点', name, state.yinbidiyuDian, this.yingbiHideArr);
			this.convertArrToHide(state, '隐蔽地域', name, state.yinbiDiyuData, this.yingbiLineHideArr);
			return;
		}
		if (importance == '集结点') {
			this.convertArrToHide(state, '集结点', name, state.jijieDian, this.jijieHideArr);
			return;
		}
		if (importance == '保障点') {
			this.convertArrToHide(state, '保障点', name, state.supportDian, this.suportHideArr);
			return;
		}
		if (importance == '防空警报点') {
			this.convertArrToHide(state, '防空警报点', name, state.baozhangDian, this.baozhangHideArr);
			return;
		}
		if (importance == '队伍点') {
			this.convertArrToHide(state, '队伍点', name, state.zhanyeDian, this.zhanyeHideArr);
			return;
		}
		if (importance == '人防点') {
			this.convertArrToHide(state, '人防点', name, state.zhihuiDian, this.zhihuiHideArr);
			return;
		}
		if (importance == '经济目标') {
			this.convertArrToHide(state, '经济目标', name, state.jingjiDian, this.jingjiHideArr);
			return;
		}
		if (importance == '物资点') {
			this.convertArrToHide(state, '物资点', name, state.wuziDian, this.wuziHideArr);
			return;
		}
	}
	public static async displaySupport(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '保障点' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '保障点') {
				treeArr = tree.children;
				break;
			}
		}

		res.data.forEach((ele) => {
			let status = '保障点' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			if (treeArr) {
				treeArr.push({ importance: '保障点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
			state.supportDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('保障点', status),
				status,
				htmlcontentstr: this.getSuSanHtmlStr(ele),
			});
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '保障点',
					data: state.supportDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static async displayJiJie(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '集结点' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '集结点') {
				treeArr = tree.children;
				break;
			}
		}

		res.data.forEach((ele) => {
			let status = '集结点' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			if (treeArr) {
				treeArr.push({ importance: '集结点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
			state.jijieDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('集结点', status),
				status,
				htmlcontentstr: this.getSuSanHtmlStr(ele),
			});
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '集结点',
					data: state.jijieDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static addToScheme(status, title, state) {
		let updateArr = this.changeChemeSeries(status, title, state, true);

		state.myChart.setOption({
			series: updateArr,
		});
	}
	public static getDianTitleInScheme(state) {
		// let realnameArr = ["集结点", "经济目标", "防空警报点", "物资点", "人防点", "队伍点", "路线点", "疏散地域点", "隐蔽地域点"];
		let arr = [
			state.supportDian,
			state.jijieDian,
			state.jingjiDian,
			state.baozhangDian,
			state.wuziDian,
			state.zhihuiDian,
			state.zhanyeDian,
			state.luxianDian,
			state.shusandiyuDian,
			state.yinbidiyuDian,
		];
		let dianTitleArr: any[] = [];
		for (const newArr of arr) {
			for (const vo of newArr) {
				if (dianTitleArr.indexOf(vo.title) != -1) continue;
				if (vo.status) {
					let len = vo.status.split('|').length;
					if (len > 1) {
						dianTitleArr.push(vo.name);
					}
				}
			}
		}
		return dianTitleArr;
	}
	private static changeChemeSeries(status, title, state, isAdd: boolean) {
		let type = status.split('|')[0];
		let arr = [
			state.supportDian,
			state.jijieDian,
			state.jingjiDian,
			state.baozhangDian,
			state.wuziDian,
			state.zhihuiDian,
			state.zhanyeDian,
			state.luxianDian,
			state.shusanLuxianData,
			state.shusandiyuDian,
			state.shusanDiyuData,
			state.yinbidiyuDian,
			state.yinbiDiyuData,
		];
		let nameArr = [
			'保障点',
			'集结点',
			'经济目标',
			'防空警报点',
			'物资点',
			'人防点',
			'队伍点',
			'疏散路线',
			'疏散路线',
			'疏散地域',
			'疏散地域',
			'隐蔽地域',
			'隐蔽地域',
		];
		let realnameArr = [
			'保障点',
			'集结点',
			'经济目标',
			'防空警报点',
			'物资点',
			'人防点',
			'队伍点',
			'路线点',
			'疏散路线',
			'疏散地域点',
			'疏散地域',
			'隐蔽地域点',
			'隐蔽地域',
		];
		let i = 0;
		let updateArr: any[] = [];
		for (const name of nameArr) {
			if (name == type) {
				let dataArr = arr[i];
				let isEdit = false;
				for (const data of dataArr) {
					if (data.name == title) {
						isEdit = true;
						if (isAdd) data.status = type + '|' + '方案';
						if (!isAdd) data.status = type;
						let ima = '';
						if (data.luIndex) ima = this.getImaByStatus(type, data.status, data.luIndex - 1);
						if (!data.luIndex && !data.coords) ima = this.getImaByStatus(type, data.status);
						if (ima) {
							data.symbol = ima;
						}
					}
				}
				if (isEdit) updateArr.push({ name: realnameArr[i], data: dataArr });
			}
			i++;
		}

		return updateArr;
	}
	public static delToScheme(status, title, state) {
		let updateArr = this.changeChemeSeries(status, title, state, false);
	}
	public static schemeUnSelectDian(schemeBack, state, optArr: string[]) {
		let backdian = schemeBack.backdian;
		let backObj = schemeBack.backObj;
		let ima = backdian.symbol.substring(0, backdian.symbol.length - 4);
		ima = ima.replace(/Select/g, '');
		backdian.symbol = ima + '.png';
		let data = this.getUpdateArr(optArr, backObj.data);
		state.myChart.setOption({
			series: [
				{
					name: backObj.name,
					data,
				},
			],
		});
	}
	public static schemeSecondPoint(seriesName, title, luIndex, state) {
		let realnameArr = ['保障点', '集结点', '经济目标', '防空警报点', '物资点', '人防点', '队伍点', '路线点', '疏散地域点', '隐蔽地域点'];
		let arr = [
			state.supportDian,
			state.jijieDian,
			state.jingjiDian,
			state.baozhangDian,
			state.wuziDian,
			state.zhihuiDian,
			state.zhanyeDian,
			state.luxianDian,
			state.shusandiyuDian,
			state.yinbidiyuDian,
		];

		let i = 0;
		let isLuXianDian = false;
		for (const realname of realnameArr) {
			if (realname == seriesName) {
				let dianArr = arr[i];
				for (const dian of dianArr) {
					if (title == dian.name) {
						if (dian.luIndex || isLuXianDian) {
							isLuXianDian = true;
							if (dian.luIndex && dian.luIndex == luIndex) return dian.value;
							continue;
						}
						return dian.value;
					}
				}
				break;
			}
			i++;
		}
		return null;
	}
	public static schemeSelectDian(seriesName, title, luIndex, state, optArr: string[]) {
		let realnameArr = ['保障点', '集结点', '经济目标', '防空警报点', '物资点', '人防点', '队伍点', '路线点', '疏散地域点', '隐蔽地域点'];
		let arr = [
			state.supportDian,
			state.jijieDian,
			state.jingjiDian,
			state.baozhangDian,
			state.wuziDian,
			state.zhihuiDian,
			state.zhanyeDian,
			state.luxianDian,
			state.shusandiyuDian,
			state.yinbidiyuDian,
		];
		let backdian = {};
		let backObj = { name: '', data: [] };
		let isLuxian = false;
		let i = 0;
		for (const realname of realnameArr) {
			if (realname == seriesName) {
				let dianArr = arr[i];
				for (const dian of dianArr) {
					if (title == dian.name) {
						if (dian.luIndex && !luIndex) return null;

						if (luIndex) {
							if (dian.luIndex && dian.luIndex == luIndex) {
								let ima = dian.symbol.substring(0, dian.symbol.length - 4);
								ima = ima.replace(/Select/g, '');
								if (ima.indexOf('Add') == -1) {
									console.error('不应该没有add');
								}
								dian.symbol = ima + 'Select.png';
								backObj.name = seriesName;
								backObj.data = dianArr;
								backdian = dian;
								let data = this.getUpdateArr(optArr, backObj.data);
								state.myChart.setOption({
									series: [
										{
											name: backObj.name,
											data,
										},
									],
								});
								break;
							}
							continue;
						}
						let ima = dian.symbol.substring(0, dian.symbol.length - 4);
						ima = ima.replace(/Select/g, '');
						if (ima.indexOf('Add') == -1) {
							console.error('不应该没有add');
						}
						dian.symbol = ima + 'Select.png';
						backObj.name = seriesName;
						backObj.data = dianArr;
						backdian = dian;
						let data = this.getUpdateArr(optArr, backObj.data);
						state.myChart.setOption({
							series: [
								{
									name: backObj.name,
									data,
								},
							],
						});
						break;
					}
				}
				break;
			}
			i++;
		}
		return { backObj, backdian };
	}
	public static async displayLuxian(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '疏散路线' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);
		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '疏散路线') {
				treeArr = tree.children;
				break;
			}
		}
		let nameArr = [];
		let luxianDianMap = {};
		res.data.forEach((ele) => {
			if (nameArr.indexOf(ele.title) == -1) nameArr.push(ele.title);
			if (!luxianDianMap[ele.title]) {
				luxianDianMap[ele.title] = [ele];
				return;
			}
			luxianDianMap[ele.title].push(ele);
		});
		for (const key in luxianDianMap) {
			let arr = luxianDianMap[key];
			for (let index = 0; index < arr.length; index++) {
				let ele = arr[index];
				let status = '疏散路线' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
				if (index == 0) {
					treeArr.push({ importance: '疏散路线', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
				}
				if (index == 0 || index == arr.length - 1) {
					state.luxianDian.push({
						name: ele.title,
						value: [ele.sourceURL, ele.imageURL, undefined],
						label: { show: index == 0 },
						symbol: this.getImaByStatus('疏散路线', status, index),
						symbolSize: [51 / 2, 76 / 2],
						status,
						luIndex: index + 1,
						htmlcontentstr: this.getSuSanHtmlStr(ele),
					});
					continue;
				}
				state.luxianDian.push({
					name: ele.title,
					value: [ele.sourceURL, ele.imageURL, undefined],
					label: { show: index == 0 },
					status,
				});
			}
		}
		//路线点
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '路线点',
					data: state.luxianDian,
				},
			],
		});
		//路线
		let cnt = 0;
		nameArr.forEach((nameEle) => {
			let j = 0,
				idx = 0;
			res.data.forEach((ele) => {
				if (nameEle == ele.title) {
					if (!j) {
						let status = '疏散路线' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
						idx =
							state.shusanLuxianData.push({
								name: nameEle,
								coords: [[ele.sourceURL, ele.imageURL]],
								status,
							}) - 1;
					} else {
						state.shusanLuxianData[idx].coords.push([ele.sourceURL, ele.imageURL]);
					}
					j++;
				}
			});
			cnt += j;
		});
		if (cnt) {
			state.myChart.setOption({
				series: [
					{
						// 根据名字对应到相应的系列
						name: '疏散路线',
						data: state.shusanLuxianData,
					},
				],
			});
		}
		return Promise.resolve();
	}
	public static async displaySuSanDiYu(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '疏散地域' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);
		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '疏散地域') {
				treeArr = tree.children;
				break;
			}
		}
		let nameArr = [];
		let cnt = 0;
		//疏散地域点
		res.data.forEach((ele) => {
			if (nameArr.indexOf(ele.title) == -1) {
				nameArr.push(ele.title);
				let status = '疏散地域' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
				state.shusandiyuDian.push({
					name: ele.title,
					value: [ele.sourceURL, ele.imageURL],
					symbol: this.getImaByStatus('疏散地域', status),
					status,
					htmlcontentstr: this.getSuSanHtmlStr(ele),
				});
				if (treeArr) {
					treeArr.push({ importance: '疏散地域', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
				}
				cnt++;
			}
		});
		if (cnt) {
			state.myChart.setOption({
				series: [
					{
						// 根据名字对应到相应的系列
						name: '疏散地域点',
						data: state.shusandiyuDian,
					},
				],
			});
		}
		//疏散地域
		cnt = 0;
		nameArr.forEach((nameEle) => {
			let j = 0,
				idx = 0;
			let startp = [];
			let endp = [];
			res.data.forEach((ele) => {
				if (nameEle == ele.title) {
					if (!j) {
						startp = [ele.sourceURL, ele.imageURL];
						let status = '疏散地域' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
						idx =
							state.shusanDiyuData.push({
								name: nameEle,
								coords: [startp],
								status,
							}) - 1;
					} else {
						endp = [ele.sourceURL, ele.imageURL];
					}
					j++;
				}
			});
			if (startp.length > 0 && endp.length > 0) {
				state.shusanDiyuData[idx].coords.push([endp[0], startp[1]], endp, [startp[0], endp[1]], startp);
			}
			cnt += j;
		});
		if (cnt) {
			state.myChart.setOption({
				series: [
					{
						// 根据名字对应到相应的系列
						name: '疏散地域',
						data: state.shusanDiyuData,
					},
				],
			});
		}
		return Promise.resolve();
	}
	public static async displayYinBiDiyu(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '隐蔽地域' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);
		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '隐蔽地域') {
				treeArr = tree.children;
				break;
			}
		}
		let nameArr = [];
		let cnt = 0;
		//疏散地域点
		res.data.forEach((ele) => {
			if (nameArr.indexOf(ele.title) == -1) {
				nameArr.push(ele.title);
				let status = '隐蔽地域' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
				state.yinbidiyuDian.push({
					name: ele.title,
					value: [ele.sourceURL, ele.imageURL, undefined],
					symbol: this.getImaByStatus('隐蔽地域', status),
					status,
					htmlcontentstr: this.getSuSanHtmlStr(ele),
				});
				if (treeArr) {
					treeArr.push({ importance: '隐蔽地域', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
				}
				cnt++;
			}
		});
		if (cnt) {
			state.myChart.setOption({
				series: [
					{
						// 根据名字对应到相应的系列
						name: '隐蔽地域点',
						data: state.yinbidiyuDian,
					},
				],
			});
		}
		//疏散地域
		cnt = 0;
		nameArr.forEach((nameEle) => {
			let j = 0,
				idx = 0;
			let startp = [];
			let endp = [];
			res.data.forEach((ele) => {
				if (nameEle == ele.title) {
					if (!j) {
						startp = [ele.sourceURL, ele.imageURL];
						let status = '隐蔽地域' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
						idx =
							state.yinbiDiyuData.push({
								name: nameEle,
								coords: [startp],
								status,
							}) - 1;
					} else {
						endp = [ele.sourceURL, ele.imageURL];
					}
					j++;
				}
			});
			if (startp.length > 0 && endp.length > 0) {
				state.yinbiDiyuData[idx].coords.push([endp[0], startp[1]], endp, [startp[0], endp[1]], startp);
			}
			cnt += j;
		});

		if (cnt) {
			state.myChart.setOption({
				series: [
					{
						// 根据名字对应到相应的系列
						name: '隐蔽地域',
						data: state.yinbiDiyuData,
					},
				],
			});
		}
		return Promise.resolve();
	}
	public static async displayBaoZhangDian(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '防空警报点' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '防空警报点') {
				treeArr = tree.children;
				break;
			}
		}
		res.data.forEach((ele) => {
			let status = '防空警报点' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			state.baozhangDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('防空警报点', status),
				status,
				htmlcontentstr: this.getSuSanHtmlStr(ele),
			});
			if (treeArr) {
				if(ele.pageviews === '（多媒体警报器）' || ele.pageviews === '（楼道型多媒体警报器）' || ele.pageviews === '（新建多媒体警报器）' ){
				 	treeArr[0].children.push({ importance: '防空警报点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
				 }else if(ele.pageviews === '（老旧新建一体机警报器）' || ele.pageviews === '（新选址一体机警报器）' || ele.pageviews === '（老旧新建一体机警报器)'){
				 	treeArr[1].children.push({ importance: '防空警报点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
				 }else {
					treeArr[2].children.push({ importance: '防空警报点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
				}
				//treeArr.push({ importance: '防空警报点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '防空警报点',
					data: state.baozhangDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static async displayJinjiDian(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		let res: any = await getArticles({ currentPage: 1, pageCount: 999999, importance: '经济目标' }, ArticleType.SSYS);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '经济目标') {
				treeArr = tree.children;
				break;
			}
		}
		res.data.forEach((ele) => {
			let status = '经济目标' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			state.jingjiDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('经济目标', status),
				status,
				htmlcontentstr: this.getJinjiHtmlStr(ele),
			});
			if (treeArr) {
				treeArr.push({ importance: '经济目标', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '经济目标',
					data: state.jingjiDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static async displaySchemeLines(state) {
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '调度中ing',
					data: state.schemelines,
				},
				{
					// 根据名字对应到相应的系列
					name: '调度中',
					data: state.schemelines,
				},
			],
		});
	}
	public static async displaWuZiDian(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		const res: any = await getArticles({ currentPage: 1, pageCount: 999999 }, ArticleType.ZBWZ);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '物资点') {
				treeArr = tree.children;
				break;
			}
		}

		res.data.forEach((ele) => {
			let status = '物资点' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			state.wuziDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('物资点', status),
				status,
				htmlcontentstr: this.getWuziHtmlstr(ele),
			});
			if (treeArr) {
				treeArr.push({ importance: '物资点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '物资点',
					data: state.wuziDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static async displayZhihuiDian(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		const res: any = await getArticles({ currentPage: 1, pageCount: 999999 }, ArticleType.ZHJG);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '人防点') {
				treeArr = tree.children;
				break;
			}
		}

		res.data.forEach((ele) => {
			let status = '人防点' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			state.zhihuiDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('人防点', status),
				status,
				htmlcontentstr: this.getZhihuiHtmlstr(ele),
			});
			if (treeArr) {
				treeArr.push({ importance: '人防点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '人防点',
					data: state.zhihuiDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static async displayZhanyeDian(state: any, schemeTitleArr: string[], treeChilds: any[]) {
		const res: any = await getArticles({ currentPage: 1, pageCount: 999999 }, ArticleType.ZYDW);
		state.getTblData.data.push(...res.data);

		let treeArr: any[] = [];
		for (const tree of treeChilds) {
			if (tree.name == '队伍点') {
				treeArr = tree.children;
				break;
			}
		}

		res.data.forEach((ele) => {
			let status = '队伍点' + (schemeTitleArr.indexOf(ele.title) != -1 ? '|方案' : '');
			state.zhanyeDian.push({
				name: ele.title,
				value: [ele.sourceURL, ele.imageURL],
				symbol: this.getImaByStatus('队伍点', status),
				status,
				htmlcontentstr: this.getDuiwuHtmlstr(ele),
			});
			if (treeArr) {
				treeArr.push({ importance: '队伍点', isleaf: true, lng: ele.sourceURL, lat: ele.imageURL, name: ele.title, id: StrUnit.getUUID() });
			}
		});
		state.myChart.setOption({
			series: [
				{
					// 根据名字对应到相应的系列
					name: '队伍点',
					data: state.zhanyeDian,
				},
			],
		});
		return Promise.resolve();
	}
	public static async deleteSchemeline(schemeval, state) {
		let i = 0;
		let isDel = false;
		for (const line of state.schemelines) {
			if (line.schemeval == schemeval) {
				state.schemelines.splice(i, 1);
				isDel = true;
				i++;
				break;
			}
			i++;
		}
		if (isDel) {
			this.displaySchemeLines(state);
		}
	}
	public static async updateGroups(optArr: string[], state, seriseName: string = '') {
		let arr = [
			state.supportDian,
			state.jijieDian,
			state.jingjiDian,
			state.baozhangDian,
			state.wuziDian,
			state.zhihuiDian,
			state.zhanyeDian,
			state.luxianDian,
			state.shusanLuxianData,
			state.shusandiyuDian,
			state.shusanDiyuData,
			state.yinbidiyuDian,
			state.yinbiDiyuData,
			state.schemelines,
			state.schemelines,
		];
		let nameArr = [
			'保障点',
			'集结点',
			'经济目标',
			'防空警报点',
			'物资点',
			'人防点',
			'队伍点',
			'路线点',
			'疏散路线',
			'疏散地域点',
			'疏散地域',
			'隐蔽地域点',
			'隐蔽地域',
			'调度中ing',
			'调度中',
		];
		this.dealArr(
			[state.luxianDian, state.shusandiyuDian, state.yinbidiyuDian],
			[state.shusanLuxianData, state.shusanDiyuData, state.yinbiDiyuData],
			['疏散路线', '疏散地域', '隐蔽地域']
		);

		let resultArr: any[] = [];
		let i = 0;

		for (const dataArr of arr) {
			if (seriseName) {
				if (seriseName == nameArr[i]) {
					let newArr = this.getUpdateArr(optArr, dataArr);
					resultArr.push({ name: nameArr[i], data: newArr });
					break;
				}
				i++;
				continue;
			}
			let newArr = this.getUpdateArr(optArr, dataArr);
			resultArr.push({ name: nameArr[i], data: newArr });
			i++;
		}
		if (resultArr.length == 0) return;
		state.myChart.setOption({
			series: resultArr,
		});
	}
	public static getWallMapPoit(state) {
		let resultArr: any[] = [];
		let i = 0;
		let arr = [
			state.supportDian,
			state.jijieDian,
			state.jingjiDian,
			state.baozhangDian,
			state.wuziDian,
			state.zhihuiDian,
			state.zhanyeDian,
			state.luxianDian,
			state.shusanLuxianData,
			state.shusandiyuDian,
			state.shusanDiyuData,
			state.yinbidiyuDian,
			state.yinbiDiyuData,
			state.schemelines,
			state.schemelines,
		];

	}
	private static getUpdateArr(optArr: any[], arr: any[]) {
		let resArr: any[] = [];
		for (const vo of arr) {
			if (vo.status) {
				let arr = vo.status.split('|');
				let newArr = arr.filter((v) => optArr.indexOf(v) > -1);
				if (newArr.length > 0) {
					resArr.push(vo);
				}
			}
		}
		return resArr;
	}
	public static async add(opt: string, state: any, isAddScheme: boolean = false) {}
	public static async delete(opt: string, state: any) {}
	public static async delay(time: number) {
		return new Promise((resolve) => {
			setTimeout(() => {
				resolve(null);
			}, time);
		});
	}
	public static getImaByStatus(type: string, status: string, index: number = -1): string {
		//normal
		if (type == '人防点') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/zhihuiAdd.png';
			return 'image://static/images/icons/zhihui.png';
		}
		if (type == '经济目标') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/jingjiAdd.png';
			return 'image://static/images/icons/jingji.png';
		}
		if (type == '队伍点') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/duiwuAdd.png';
			return 'image://static/images/icons/duiwu.png';
		}
		if (type == '集结点') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/jijieAdd.png';
			return 'image://static/images/icons/jijie.png';
		}
		if (type == '物资点') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/wuAdd.png';
			return 'image://static/images/icons/wu.png';
		}
		if (type == '防空警报点') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/baozhangAdd.png';
			return 'image://static/images/icons/baozhang.png';
		}
		if (type == '保障点') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/supportAdd.png';
			return 'image://static/images/icons/support.png';
		}
		if (type == '疏散路线' && index >= 0) {
			let arr = status.split('|');
			if (arr.length >= 2) {
				if (index != 0) {
					return 'image://static/images/icons/luzhongAdd.png';
				}
				return 'image://static/images/icons/luqiAdd.png';
			}

			if (index != 0) {
				return 'image://static/images/icons/luzhong.png';
			}
			return 'image://static/images/icons/luqi.png';
		}
		if (type == '疏散地域') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/shusanAdd.png';
			return 'image://static/images/icons/shusan.png';
		}
		if (type == '隐蔽地域') {
			let arr = status.split('|');
			if (arr.length >= 2) return 'image://static/images/icons/yinbiAdd.png';
			return 'image://static/images/icons/yinbi.png';
		}
		return '';
	}
	private static susantHeader = ['电话', '联系人', '类型', '所属区域', '位置', '备注'];
	private static susanfilterVal = ['timestamp', 'reviewer', 'importance', 'status', 'pageviews', 'fullContent'];
	private static jingjitHeader = ['编号', '时间', '名称', '类型', '重要性', '价值/规模', '状态'];
	private static jingjifilterVal = ['abstractContent', 'timestamp', 'title', 'author', 'status', 'pageviews', 'fullContent'];
	private static wuzitHeader = ['编号', '电话', '名称', '类型', '联系人', '管理单位', '位置', '所属区域'];
	private static wuzifilterVal = ['abstractContent', 'timestamp', 'title', 'author', 'reviewer', 'importance', 'pageviews', 'status'];
	private static filterValtwo = ['rowZero', 'rowOne', 'rowTwo'];
	private static wuziheader = ['物资', '数量', '备注'];
	private static duiwuheader = ['人员', '号码', '备注'];
	private static zhihuiheader = ['成员', '号码', '备注'];
	private static duiwutHeader = ['编号', '电话', '名称', '类型', '管理单位', '人数', '组织建制'];
	private static duiwufilterVal = ['abstractContent', 'timestamp', 'title', 'author', 'importance', 'pageviews', 'status'];
	private static zhihuitHeader = ['名称', '电话', '成员单位', '级别', '主要职责'];
	private static zhihuifilterVal = ['title', 'timestamp', 'author', 'importance', 'pageviews'];
	public static getSuSanHtmlStr(data: any) {
		let htmlstr = this.gethtmlStr(data, this.susantHeader, this.susanfilterVal);
		return htmlstr;
	}
	public static getJinjiHtmlStr(data: any) {
		let htmlstr = this.gethtmlStr(data, this.jingjitHeader, this.jingjifilterVal, true, '经济目标');
		return htmlstr;
	}
	public static getWuziHtmlstr(data: any): string {
		let htmlstr = this.gethtmlStr(data, this.wuzitHeader, this.wuzifilterVal);
		let arr = JSON.parse(data.fullContent);
		let i = 1;
		for (const detialdata of arr) {
			let otherStr = this.gethtmlStr(detialdata, this.wuziheader, this.filterValtwo, false);
			htmlstr += otherStr;
			if (i == 3) {
				htmlstr += `<div><span style="display:inline-block;margin-right:4px;
        border-radius:10px;width:10px;height:10px;
        background-color:#91cc75;"></span>
                    <span style="margin-right:10%;">点击查看更多>></span></div>`;
				break;
			}

			i++;
		}
		return htmlstr;
	}
	public static getDuiwuHtmlstr(data: any): string {
		let htmlstr = this.gethtmlStr(data, this.duiwutHeader, this.duiwufilterVal);
		let arr = JSON.parse(data.fullContent);
		let i = 1;
		for (const detialdata of arr) {
			let otherStr = this.gethtmlStr(detialdata, this.duiwuheader, this.filterValtwo, false);
			htmlstr += otherStr;
			if (i == 3) {
				htmlstr += `<div><span style="display:inline-block;margin-right:4px;
        border-radius:10px;width:10px;height:10px;
        background-color:#91cc75;"></span>
                    <span style="margin-right:10%;">点击查看更多>></span></div>`;
				break;
			}

			i++;
		}
		return htmlstr;
	}
	public static getZhihuiHtmlstr(data: any): string {
		let htmlstr = this.gethtmlStr(data, this.zhihuitHeader, this.zhihuifilterVal);
		// let arr = JSON.parse(data.fullContent);
		// for (const detialdata of arr) {
		//   let otherStr = this.gethtmlStr(detialdata,this.zhihuiheader,this.filterValtwo,false);
		//   htmlstr+=otherStr;
		// }
		return htmlstr;
	}
	private static gethtmlStr(data, tHeader, filterVal, isHasTitle = true, type: string = ''): string {
		let htmlstr = '';
		if (isHasTitle) {
			htmlstr = `<div>${data.title}</div>`;
			for (let index = 0; index < tHeader.length; index++) {
				const ti = tHeader[index];
				const key = filterVal[index];
				let value = data[key];
				if (type == '经济目标' && key == 'timestamp') {
					value = GlobalConfig.moment(parseInt(value + '')).format('YYYY-MM-DD HH:mm:ss');
				}
				htmlstr += `<div><span style="display:inline-block;margin-right:4px;
        border-radius:10px;width:10px;height:10px;
        background-color:#91cc75;"></span>
                    <span style="margin-right:10%;">${ti}：${value}</span></div>`;
			}
			return htmlstr;
		}
		let i = 1;
		let contentstr = '';
		for (let index = 0; index < tHeader.length; index++) {
			const ti = tHeader[index];
			const key = filterVal[index];
			contentstr += `${ti}：${data[key]}，`;
			if (i == 3) {
				contentstr = contentstr.substring(0, contentstr.length - 1);
				htmlstr += `<div><span style="display:inline-block;margin-right:4px;
        border-radius:10px;width:10px;height:10px;
        background-color:#91cc75;"></span>
                    <span style="margin-right:10%;">${contentstr}</span></div>`;
				i = 1;
				contentstr = '';
			}

			i++;
		}
		return htmlstr;
	}
	private static dealArr(statusArr: any[], dataArr: any[], nameArr: string[]) {
		let map = {};
		for (const arr of statusArr) {
			for (const obj of arr) {
				if (obj && obj.status.indexOf('|') != -1) {
					map[obj.name] = 1;
				}
			}
		}
		for (let i = 0; i < dataArr.length; i++) {
			let arr = dataArr[i];
			let name = nameArr[i];
			for (let j = 0; j < arr.length; j++) {
				let data = arr[j];
				data.status = name;
				for (let kk = 0; kk < data.coords.length; kk++) {
					data.coords[kk] = [data.coords[kk][0], data.coords[kk][1]];
				}
				if (map[data.name]) {
					data.status += '|方案';
				}
			}
		}
	}
	private static convertArrToHide(state: any, saveName: string, name: string, nowArr: any[], saveArr: any[]) {
		let isDel = false;
		for (let i = nowArr.length - 1; i >= 0; i--) {
			let data = nowArr[i];
			if (name == data.name) {
				isDel = true;
				saveArr.push({ ...data });
				nowArr.splice(i, 1);
			}
		}
		if (isDel) {
			for (const data of this.changeDisplayArr) {
				if (data.name == saveName) {
					return;
				}
			}
			this.changeDisplayArr.push({
				name: saveName,
				data: nowArr,
			});
		}
	}
	private static convertArrToDisplay(state: any, saveName: string, name: string, nowArr: any[], saveArr: any[]) {
		let isAdd = false;
		for (let i = saveArr.length - 1; i >= 0; i--) {
			let data = saveArr[i];
			if (name == data.name) {
				isAdd = true;
				nowArr.push(data);
				saveArr.splice(i, 1);
			}
		}
		if (isAdd) {
			for (const data of this.changeDisplayArr) {
				if (data.name == saveName) {
					return;
				}
			}
			this.changeDisplayArr.push({
				name: saveName,
				data: nowArr,
			});
		}
	}
	public static getTeamId(treeChildArr: any[], seriesName: string) {
		for (const child of treeChildArr) {
			if (child.name == seriesName) {
				return child.id;
			}
		}
	}
	/**
	 * 显示特定专业队伍
	 */
	public static displayOneTeam(state: any, treeChildArr: any[], arr: any[], pageType: string, teamIdArr: any[]) {
		let dataArr: any[] = [];
		let hideVoArr: any[] = [];
		for (const child of treeChildArr) {
			if (child.name == '队伍点') {
				dataArr = child.children;
				teamIdArr.push(child.id);
				break;
			}
		}
		if (dataArr.length <= 0) return hideVoArr;
		if (pageType == '医疗队伍') {
			return this.diplayteamOne(state, '医疗', arr, hideVoArr, dataArr);
		}
		if (pageType == '治安队伍') {
			return this.diplayteamOne(state, '治安', arr, hideVoArr, dataArr);
		}
		if (pageType == '通信队伍') {
			return this.diplayteamOne(state, '通信', arr, hideVoArr, dataArr);
		}
		if (pageType == '抢险队伍') {
			return this.diplayteamOne(state, '抢险', arr, hideVoArr, dataArr);
		}
		if (pageType == '运输队伍') {
			return this.diplayteamOne(state, '运输', arr, hideVoArr, dataArr);
		}
		if (pageType == '防化队伍') {
			return this.diplayteamOne(state, '防化', arr, hideVoArr, dataArr);
		}
		if (pageType == '心理队伍') {
			return this.diplayteamOne(state, '心理', arr, hideVoArr, dataArr);
		}
		return hideVoArr;
	}
	private static diplayteamOne(state: any, teamName: string, arr: any[], hideVoArr: any[], dataArr: any[]) {
		for (const data of arr) {
			if (data.name.indexOf(teamName) != -1) {
				let lng = data.value[0];
				let lat = data.value[1];
				let point = new BMap.Point(lng, lat);
				(state.bmap as any).centerAndZoom(point, window['bdmapLevel']);
				break;
			}
		}
		for (const vo of dataArr) {
			if (vo.name.indexOf(teamName) == -1) {
				hideVoArr.push(vo);
			}
		}
		return hideVoArr;
	}
	private static toMoveOne(state: any, saveName: string, name: string, nowArr: any[], saveArr: any[], lng: string, lat: string) {
		for (const vo of nowArr) {
			if (name == vo.name) {
				vo.value = [lng, lat];
				state.myChart.setOption({
					series: [
						{
							// 根据名字对应到相应的系列
							name: saveName,
							data: nowArr,
						},
					],
				});
				break;
			}
		}
	}
}
